﻿using System.Globalization;
using System.Windows.Controls;

namespace Handy.Gd.WpfUserControl.Tools
{
    public class NumericUpDownDemoRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            double doubleValue = 0;
            if (!(value is  double))
            {
                return new ValidationResult(false, HandyControl.Properties.Langs.Lang.FormatError);
            }
            else
            {
                doubleValue = (double)value;
            }

            return doubleValue % 2 > double.Epsilon
                ? new ValidationResult(false, Properties.Langs.Lang.Error)
                : ValidationResult.ValidResult;
        }
    }
}